<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Ad extends Model
{
    protected $table = 'ad';

    protected $primaryKey = 'ad_id';

    public $timestamps = false;
    //白名单
    protected $fillable = [
        'ad_id', //广告id
        'site_id', //广告位id
        'city_id', //城市id
        'title', //广告标题
        'photo', //图片
        'photo_oss',
        'bg_date', //广告开始时间
        'end_date', //广告结束时间
        'orderby', //
        'type', //跳转类型1-商家 2-团购3-链接
        'goal', //根据type存的目标
        'cilcknum', //点击量
        'closed', //1为未删除，2为已删除（默认为1）
    ];

    protected $casts = ['photo'];

    public function getPhotoAttribute($value)
    {
        return \App\Library\HandleFile::handleFilePath($value, $this->photo_oss);
    }

    //关联团购
    public function tuan_info()
    {
        return $this->hasOne('App\\Models\\TuanInfo', 'tuan_id', 'goal');
    }

    //商铺
    public function shop()
    {
        return $this->hasOne('App\\Models\\Shop', 'shop_id', 'goal');
    }

    //关联用户评论 （商铺）
    public function shop_comments()
    {
        return $this->hasMany('App\\Models\\UserComment', 'shop_id', 'goal');
    }

    //关联用户评论（团购）
    public function tuan_comments()
    {
        return $this->hasMany('App\\Models\\UserComment', 'tuan_id', 'goal');
    }
}
